import {inject, observer} from "mobx-react";
import React from "react";
import * as asyncLoad from '../util/asyncLoad';
import {workflowPublicFiles} from "../constants/fileConfig";
import Loading from "./Loading";
import base from "../util/base";
import * as authTypes from "../constants/secondAuthType";

export default class Main extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            hasLoad: false,
            store: null
        };
    }

    componentDidMount() {
        const init = () => {
            const {SecondAuthStore} = window.weaWorkflowPublic;     //公共组件的store，与本组件的secondAuthStore不同，请注意
            this.setState({hasLoad: true, store: SecondAuthStore});
        }
        asyncLoad.asyncLoadModule('workflowPublic', workflowPublicFiles, init);
    }

    //关闭窗口
    onClose = () => {
        const {globalStore} = base;
        globalStore.controlDialogVisible(authTypes.AUTH_DETAIL_DIALOG, false);
    }

    render() {
        const {hasLoad, store} = this.state;

        const {dialogVisible, commonParam} = base.globalStore;
        const {visible} = this.props;

        if (hasLoad) {
            store.setCommonParam(commonParam);
            const {SecondAuthDetailCom} = window.weaWorkflowPublic;
            return (
                <SecondAuthDetailCom ecId={`${this && this.props && this.props.ecId || ''}_SecondAuthDetailCom@6dydvt`}
                    visible={visible}
                    secondAuthStore={store}
                    commonParam={commonParam}
                    onClose={this.onClose}/>
            )
        } else {
            return (<Loading ecId={`${this && this.props && this.props.ecId || ''}_Loading@s3qxtv`} />);
        }
    }
}